﻿var Bom = {};
//设置
Bom.settings = {
    TaskId: com.get.Id,
    TaskCode: "",
    Action: null,
    editRow: undefined,
    ColumnsParam: [],
    currentTr: null,
    MPState: "",
    MPType: "",
    SubmitType: "",
    EquipId: 0,
    CopySwitch: "1",//0代表复制开关打开，1代表关闭
};
var searchAction = "bomSearch";
Bom.init = function () {
    $("#TaskId").val(Bom.settings.TaskId);
    //加载任务信息
    com.ajax({
        url: "/Logic/TM/TaskManagerAjax.aspx?method=GetTaskInfoByPrimaryId&TaskId=" + Bom.settings.TaskId, success: function (data) {
            $("#lblTaskCode").html(data.TaskCode);
            $("#lblProjName").html(data.ProjName);
            $("#lblEngName").html(data.EngName);
            $("#lblNum").html(data.TaskNum);
            $("#lblEquipName").html(data.EquipName);
            $("#lblEquipModel").html(data.EquipModel);
            $("#lblTaskWeight").html(data.BomWeight);
            $("#hidEquipId").val(data.EquipId);
            $("#lblTaskState").html(com.getArrayText(StaticCombo.TaskState, data.State));
            if (data.State == "2" || data.State == "6") {
                $("#btnSubmitPlan").linkbutton("disable");
            }
            Bom.settings.TaskCode = data.TaskCode;
            Bom.settings.EquipId = data.EquipId;
            Bom.settings.EquipModel = data.EquipModel;
        }
    });

    var height = $("#divTotal").height();

    var master = $("#master").height();
    var content = parseFloat(height) - parseFloat(master) - 45;
    $("#tbList").css("height", content);

    //加载原始数据列表
    $("#tbList").datagrid({
        url: '/Logic/TM/OrgDataAjax.aspx?method=GetOrgDataByTaskId',
        loadMsg: '数据加载中请稍后……',
        // fitColumns: true,
        pagination: true,
        rownumbers: true,
        idField: "ID",
        singleSelect: false,
        autoRowHeight: false,
        nowrap: true,
        pageSize: 20,
        pageList: [20, 50, 100, 500],
        queryParams: com.serializeSearchArray("form1"),

        frozenColumns: [[{ field: 'ck', checkbox: true, width: 30 },
        {
            field: 'MpState', title: 'C ', align: "center", width: 20, formatter: function (value, row, Index) {

                return com.getArrayText(StaticCombo.OrgAuditState, row.MpReviewState);
            }, styler: function (value, row, index) {
                if (row.MpState == "1") {
                    return 'background-color:green';
                }
                else if (row.MpState == "2") {
                    return 'background-color:red';
                }
                else if (row.MpState == "3") {
                    return 'background-color:gray';
                } else if (row.MpState == "4") {
                    return 'background-color:#49C4FA';
                }
            }
        },
         {
             field: 'MsState', title: 'Z ', align: "center", width: 20, formatter: function (value, row, Index) {

                 return com.getArrayText(StaticCombo.OrgAuditState, row.MsReviewState);
             }, styler: function (value, row, index) {
                 if (row.MsState == "1") {
                     return 'background-color:green';
                 }
                 else if (row.MsState == "2") {
                     return 'background-color:red';
                 }
                 else if (row.MsState == "3") {
                     return 'background-color:gray';
                 }
                 else if (row.MsState == "4") {
                     return 'background-color:#49C4FA';
                 }

             }
         },
                  {
                      field: 'JsState', title: 'J', align: "center", width: 20, formatter: function (value, row, Index) {

                          return com.getArrayText(StaticCombo.OrgAuditState, row.JsReviewState);
                      }, styler: function (value, row, index) {
                          if (row.JsState == "1") {
                              return 'background-color:green';
                          }
                          else if (row.JsState == "2") {
                              return 'background-color:red';
                          }
                          else if (row.JsState == "3") {
                              return 'background-color:gray';
                          } else if (row.JsState == "4") {
                              return 'background-color:#49C4FA';
                          }
                      }
                  },
         {
             field: 'OsState', title: 'W ', align: "center", width: 20, formatter: function (value, row, Index) {

                 return com.getArrayText(StaticCombo.OrgAuditState, row.OsReviewState);
             }, styler: function (value, row, index) {
                 if (row.OsState == "1") {
                     return 'background-color:green';
                 }
                 else if (row.OsState == "2") {
                     return 'background-color:red';
                 }
                 else if (row.OsState == "3") {
                     return 'background-color:gray';
                 } else if (row.OsState == "4") {
                     return 'background-color:#49C4FA';
                 }
             }
         },
                 {
                     field: 'MapAssState', title: 'T ', align: "center", width: 20, formatter: function (value, row, index) { return row.MapAssState == "2" ? "Y" : "" }, styler: function (value, row, index) {
                         if (row.MapAssState == "1" || row.MapAssState == "2") {
                             return 'background-color:green';
                         } else if (row.ClassId != 0 && typeof (row.ClassId) != undefined) {
                             return 'background-color:#F3ED77';
                         }
                     }
                 }, {
                     field: 'MkState', title: 'M ', align: "center", width: 20, formatter: function (value, row, Index) {

                         return com.getArrayText(StaticCombo.OrgAuditState, row.MkReviewState);
                     }, styler: function (value, row, index) {
                         if (row.MkState == "1") {
                             return 'background-color:green';
                         }
                         else if (row.MkState == "2") {
                             return 'background-color:red';
                         }
                         else if (row.MkState == "3") {
                             return 'background-color:gray';
                         } else if (row.MkState == "4") {
                             return 'background-color:#49C4FA';
                         }
                     }
                 },
                  {
                      field: 'IsReplace', title: '代', align: "center", width: 20, formatter: function (value, row, Index) {

                          if (value == "1") {
                              return '<a href="#" title="规格：' + row.RePlaceGuige + '，材质：' + row.RePlaceCaizhi + '" class="note" style="text-decoration:none;color:red">代</a>';

                          }
                          else {
                              return "";
                          }
                      }, styler: function (value, row, index) {
                          if (value == "1") {
                              return 'cursor:pointer';
                          }

                      }
                  },

                  { field: 'Xuhao', title: '序号', align: "center", width: 100 },
                    { field: 'Zongxu', title: '总序', align: "center", width: 70 },
         { field: 'MsXuhao', title: '明细序号', align: "center", width: 70 },

         { field: 'Map', title: '图号', align: "center", width: 120 },
         { field: 'MaterialCode', title: '物料编码', align: "center", width: 100 },

         { field: 'MaterialName', title: '物料名称', align: "center", width: 120 }]],
        columns: [[
              { field: 'PartName', title: '子项名称', align: "center", width: 120 },
         { field: 'MaterialGuige', title: '规格', align: "center", width: 100 },
         { field: 'Ku', title: 'K ', align: "center", width: 20 },
        // { field: 'KeyPart', title: '关键部件 ', align: "center" },
         { field: 'SingleNum', title: '单台数量 ', align: "center", width: 40 },
         { field: 'Num', title: '数量 ', align: "center", width: 40 },
         { field: 'UnitWeight', title: '单重(kg) ', align: "center", width: 70 },
         { field: 'TotalWeight', title: '总重(kg) ', align: "center", width: 70 },
         { field: 'MaterialGB', title: '国标', align: "center", width: 120 },
         { field: 'HidGuige', title: '材料规格', align: "center", width: 100 },
         { field: 'Length', title: '材料长度', align: "center", width: 60 },
         { field: 'Width', title: '材料宽度 ', align: "center", width: 60 },
         { field: 'MaterialTheroWeight', title: '理论重量', align: "center", width: 60 },
         { field: 'MaUnitWeight', title: '材料单重', align: "center", width: 70 },
         { field: 'MaTotalWeight', title: '材料总重', align: "center", width: 70 },
         { field: 'TotalLength', title: '材料总长', align: "center", width: 60 },
         { field: 'Area', title: '面域', align: "center", width: 60 },
          { field: 'AreaPerDun', title: '吨表面积 ', align: "center", width: 100, },
         { field: 'PlanArea', title: '计划面域', align: "center", width: 70 },
         { field: 'MaterialCaizhi', title: '材质 ', align: "center", width: 100 },
         { field: 'MaState', title: '毛胚状态 ', align: "center", width: 60 },
         {
             field: 'Process', title: '工艺流程 ', align: "center", width: 70, formatter: function (value, row, Index) {

                 return com.getArrayText(StaticCombo.Process, value);
             }
         },
         { field: 'IsFixedSize', title: '是否定尺 ', align: "center", width: 60 },
         { field: 'SelfWeight', title: '部件自重 ', align: "center", width: 60 },
         { field: 'IsSubmitMs', title: '制作明细 ', align: "center", width: 60 },
         { field: 'IsSubmitMp', title: '材料计划 ', align: "center", width: 60 },
          {
              field: 'BlankType', title: '下料类别 ', align: "center", width: 70, formatter: function (value, row, Index) {

                  return com.getArrayText(StaticCombo.BlankType, value);
              }
          },
           { field: 'FillDate', title: '操作时间 ', align: "center", width: 140, sortable: true },
         { field: 'ClassName', title: '制作班组 ', align: "center", width: 90 },
         { field: 'Note', title: '备注', align: "center", width: 350 },
         { field: 'RePlaceGuige', title: '代用规格', align: "center", width: 100 },
         { field: 'RePlaceCaizhi', title: '代用材质', align: "center", width: 100 },
          { field: 'OrgMaterialName', title: '原始物料名称', align: "center", width: 80 }
        ]]
    });


    //加载操作列的显示隐藏数据
    com.ajax({
        url: '/Logic/TM/OrgDataAjax.aspx?method=GetPersonColumn', success: function (data) {
            Bom.settings.ColumnsParam = data;
            $("#divOperate").dialog("close");
        }
    });



    //初始化高级筛选窗口
    //初始化列显示隐藏界面
    $('#divHighSearch').dialog({
        title: '高级筛选',
        width: 560,
        height: 320,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: true,
        href: '/UI/BD/HighSearchWindow.aspx?action=bomSearch',
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                $.extend(o, com.serializeSearchArray("form1"));
                $.extend(o, com.getHighSearchList());
                $("#tbList").datagrid("load", o);
                $("#divHighSearch").dialog("close");
            }
        }, { text: "取消", handler: function () { $("#divHighSearch").dialog("close"); } }]
    });
    $("#divHighSearch").dialog("close");





    //初始化列显示隐藏界面
    $('#divColumn').dialog({
        title: '编辑窗口',
        width: 630,
        height: 400,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true
    });
    $("#divColumn").dialog("close");



    //初始化增加前缀序号界面
    $('#divMap').dialog({
        title: '前缀图号',
        width: 180,
        height: 120,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var rows = $("#tbList").datagrid("getSelections");
                var txtFrontMap = $("#frontMap").val();
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=AddFrontMap", data: { FrontMap: txtFrontMap, orgData: JSON.stringify(rows), CopySwitch: Bom.settings.CopySwitch }, success: function (data) {
                        var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };

                        $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                        $("#tbList").datagrid("unselectAll");
                        com.message(data.state, data.msg, function () {
                            $("#divMap").dialog("close");
                        });

                    }
                });
            }
        }, { text: "取消", handler: function () { $("#divMap").dialog("close"); } }]
    });
    $("#divMap").dialog("close");


    //初始化列显示隐藏界面
    $('#divCopyData').dialog({
        title: '复制数据',
        width: 300,
        height: 200,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var row = $("#tbList").datagrid("getSelected");
                var txtCopyXuhao = $("#txtCopyXuhao").val();
                // $.extend(row, { Xuhao: txtCopyXuhao, TaskId: Bom.settings.TaskId });
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=CopyOrgData", data: { Id: row.ID, Xuhao: txtCopyXuhao, TaskId: Bom.settings.TaskId, txtBeforeMap1: $("#txtBeforeMap1").val(), txtAfterMap1: $("#txtAfterMap1").val(), txtBeforeMap2: $("#txtBeforeMap2").val(), txtAfterMap2: $("#txtAfterMap2").val() }, success: function (data) {
                        var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                        $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                        $("#tbList").datagrid("unselectAll");
                        com.message(data.state, data.msg, function () {
                            $("#divCopyData").dialog("close");
                        });

                    }
                });
            }
        }, { text: "取消", handler: function () { $("#divCopyData").dialog("close"); } }]
    });
    $("#divCopyData").dialog("close");
}

//主数据查询
Bom.Search = function () {
    var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
    $.extend(o, com.serializeSearchArray("form1"));
    $.extend(o, com.getHighSearchList());
    $("#tbList").datagrid("load", o);
    // $("#tbList").datagrid("unselectAll");
    $("#divSearchShow").toggle();
}

Bom.Reset = function () {
    Bom.settings.MPState = "";
    Bom.settings.MPType = "";
    $("#lblMPType").html("");
    $("#form1").form("reset");
    $("#highSearchForm").form("reset");
    var para = com.serializeSearchArray("form1");
    $("#tbList").datagrid("load", para);
    $("#tbList").datagrid("unselectAll");
}


//查询面板显示隐藏
Bom.SearchShow = function () {

    $("#divSearchShow").toggle();
}


Bom.OpenEditWin = function () {

    $("#divOperate").dialog("open");
}


//高级查询 
Bom.HighSearch = function () {

    $("#divHighSearch").dialog("open");
}

//新增
Bom.AddOrgData = function () {

    com.message("confirm", "您确定新增数据吗？请注意：该操作可能会刷现未保存的数据", function (r) {
        if (r) {
            top.wrapper.addTab("新增原始数据", "/UI/TM/OrgDetailEdit.aspx?action=add&TaskId=" + Bom.settings.TaskId);
        }
    })
}

//编辑
Bom.EditOrgData = function () {
    Bom.settings.Action = "edit";
    //  $("#XuhaoModel").combobox("setValue", "1");
    var rows = $("#tbList").datagrid("getSelections");
    var orgIds = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].MpReviewState == "2" || rows[i].MsReviewState == "2" || rows[i].OsReviewState == "2" || rows[i].MpReviewState == "1" || rows[i].MsReviewState == "1" || rows[i].OsReviewState == "1" || rows[i].MkReviewState == "1") {
                com.message("information", "该条记录正在审核中，无法编辑");
                return;
            }
            else {
                orgIds += rows[i].ID + ",";
            }
        }
        top.wrapper.addTab("原始数据编辑", "/UI/TM/OrgDetailEdit.aspx?action=edit&TaskId=" + Bom.settings.TaskId + "&orgIds=" + orgIds.trim(','));
    }
    else {
        com.message("information", "请选中一行");
    }
}


//只编辑明细
Bom.EditMsOrgData = function () {
    Bom.settings.Action = "edit";
    //  $("#XuhaoModel").combobox("setValue", "1");
    var rows = $("#tbList").datagrid("getSelections");
    var orgIds = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            orgIds += rows[i].ID + ",";

        }
        top.wrapper.addTab("原始数据明细编辑", "/UI/TM/OrgDetailEdit.aspx?action=editMs&TaskId=" + Bom.settings.TaskId + "&orgIds=" + orgIds.trim(','));
    }
    else {
        com.message("information", "请选中一行");
    }
}

Bom.DeleteOrg = function () {
    var rows = $("#tbList").datagrid("getSelections");
    var Xuhao = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            Xuhao += rows[i].Xuhao + ","
        }
        Xuhao.trim(',');
        com.message("confirm", "您确定要删除序号为【" + Xuhao + "】的记录吗？", function (r) {
            if (r) {
                //  alert("a");
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=DeleteOrg", data: { TaskId: Bom.settings.TaskId, data: JSON.stringify(rows) }, success: function (data) {
                        com.message(data.state, data.msg, function () {
                            var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                            $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                            $("#tbList").datagrid("unselectAll");

                        })
                    }
                });
            }

        })
    }
    else {
        com.message("information", "请选中一行");
    }
}




//导入数据
Bom.ExportHistory = function () {

    var taskId = $("#TaskId").val();
    top.wrapper.addTab("数据导入", "/UI/TM/OrgDataExport.aspx?TaskId=" + taskId);


}


//复制数据
Bom.CopyData = function () {
    var row = $("#tbList").datagrid("getSelected");
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length == 1) {
        $("#divCopyData").dialog("open");
    }
    else {
        com.message("information", "请选择一条数据");
    }
}


//批量复制数据
Bom.BatchCopyData = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 1) {
        var Ids = "";
        for (var i = 0; i < rows.length; i++) {
            Ids += rows[i].ID + ",";
        }
        top.wrapper.addTab("批量复制", "/UI/TM/OrgDetailEdit.aspx?action=batch&TaskId=" + Bom.settings.TaskId + "&Ids=" + Ids);
    }
    else {
        com.message("information", "请选择一条数据");
    }
}




Bom.EditCopySwitch = function () {
    if (Bom.settings.CopySwitch == "0") {
        Bom.settings.CopySwitch = "1";
        $("#CopySwitch").html("关");
    }
    else {
        Bom.settings.CopySwitch = "0";
        $("#CopySwitch").html("开");
    }
}


//增加前缀图号
Bom.AddFrontMap = function () {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        $("#divMap").dialog("open");
    } else {
        com.message("information", "请选择至少一条数据");
    }
}



//清空前缀图号
Bom.DeleteFrontMap = function () {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=DeleteFrontMap", data: { orgData: JSON.stringify(rows) }, success: function (data) {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                $("#tbList").datagrid("unselectAll");
                com.message(data.state, data.msg);

            }
        });
    } else {
        com.message("information", "请选择至少一条数据");
    }
}


//列窗口打开
Bom.ColumnShow = function () {
    $("#divColumn").dialog("open");

    //加载原始数据列表
    $("#tbColumn").datagrid({
        url: "/Logic/TM/OrgDataAjax.aspx?method=GetBomColumns",
        loadMsg: '数据加载中请稍后……',
        fitColumns: true,
        rownumbers: true,
        idField: "FieldId",
        singleSelect: true,
        striped: true,
        columns: [[
             { field: 'TableEngName', title: '表格 ', align: "center" },
             { field: 'TableName', title: '表名称 ', align: "center" },
             { field: 'Field', title: '字段 ', align: "center", width: 80 },
             { field: 'Title', title: '标题 ', align: "center" },
   {
       field: 'Length', title: '列宽度 ', align: "center", editor: {
           type: "numberbox",
           options: {
               required: true
           }
       }
   },
    {
        field: 'OrderField', title: '排序 ', align: "center", editor: {
            type: "validatebox",
            options: {

            }
        }
    },
             {
                 field: 'IsHidden', title: '是否显示 ', align: "center", editor: {
                     type: "combobox",
                     options: {
                         data: StaticCombo.ColumnShown,
                         valueField: 'value',
                         textField: 'text',
                         panelHeight: 'auto'

                     }
                 }, formatter: function (value, row, index) {
                     return com.getArrayText(StaticCombo.ColumnShown, value);
                 }
             },
        ]], onDblClickRow: function (rowIndex, rowData) {
            if (Bom.settings.editRow == undefined) {
                $("#tbColumn").datagrid("beginEdit", rowIndex);
                Bom.settings.editRow = rowIndex;
            }
            else {
                $('#tbColumn').datagrid('endEdit', Bom.settings.editRow);
            }
        }, onAfterEdit: function (rowIndex, rowData, changes) {
            com.ajax({
                url: "/Logic/TM/OrgDataAjax.aspx?method=SaveColumnShown",
                data: rowData,
                success: function (data) {
                    com.message(data.state, data.msg, function () { $("#tbColumn").datagrid("reload"); });
                    $("#tbList").datagrid("unselectAll");
                }
            });

            Bom.settings.editRow = undefined;
        }
    });

}

//下推图纸分工
Bom.MapAssPushDown = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].MapAssState == "2" || rows[i].MapAssState == "1") {
                com.message("information", "序号为【" + rows[i].Xuhao + "】已经下推任务单，操作被终止！");
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=MapAssPushDown", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows) }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

//公布分工数据
Bom.UploadAssignData = function () {

    com.ajax({
        data: { TaskId: Bom.settings.TaskId },
        url: "/Logic/TM/OrgDataAjax.aspx?method=UploadAssignData",
        success: function (data) {
            com.message(data.state, data.msg);
            $("#tbList").datagrid("reload");
        }
    });
}


//标记为
Bom.MarkAs = function (type, state) {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if ((rows[i].MpReviewState == "1" && type == "MpState") || (rows[i].MsReviewState == "1" && type == "MsState") || (rows[i].OsReviewState == "1" && type == "OsState") || ((rows[i].JsReviewState == "1" && type == "JsState")) || ((rows[i].MkReviewState == "1" && type == "MkState"))) {
                com.message("information", "勾选的记录正在审核，无法被标记！")
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=MarkAsState", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows), type: type, state: state, CopySwitch: Bom.settings.CopySwitch }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

Bom.ExportBlankPlan = function () {
   
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        var Ids = "";
        for (var i = 0; i < rows.length; i++) {
            Ids += rows[i].ID + ",";
        }
        top.wrapper.addTab("下料计划Excel", "/ExportModel/OrgBlankExport.aspx?taskId=" + Bom.settings.TaskId + "&Ids=" + Ids);
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}


Bom.MPSearch = function (MPType, MPState, SubmitType) {
    $("#tbList").datagrid("clearSelections");
    Bom.settings.MPState = MPState;
    Bom.settings.MPType = MPType;
    Bom.settings.SubmitType = SubmitType;
    $("#lblMPType").html(MPType);
    var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
    //$("#form1").form("reset");
    var param = com.serializeSearchArray("form1");
    $("#tbList").datagrid("load", $.extend(param, o));
    $("#tbList").datagrid("unselectAll");
}


Bom.SubmitChange = function (type, level) {
    var rows = $("#tbList").datagrid("getSelections");
    if (Bom.settings.MPState == "" || Bom.settings.MPType == "") {
        com.message("information", "请先选择提交类别！");
        return;
    }
    var MPType = Bom.settings.MPType;
    var MPState = Bom.settings.MPState;
    var Ids = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            var item = rows[i];
            if (MPType == "定尺板" || MPType == "非定尺板" || MPType == "型材" || MPType == "标(发运)" || MPType == "标(组装)") {

                if (item.MaterialCode != "") {
                    if (MPState == "Normal") {
                        if (item.MpState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                    }
                    else if (MPState == "Change") {
                        if (item.MpState != "2" && item.MpState != "3") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                            return;
                        }
                        if (item.MpReviewState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                            return;
                        }
                    }
                }
                else {
                    com.message("error", "序号为【" + item.Xuhao + "】的物料编码为空，提交被终止！");
                    return;
                }
            }
            else if (MPType == "制作报量") {
                //console.log(item.MaterialCode);
                if (MPState == "Normal") {
                    if (item.MsState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                        return;
                    }
                    if (item.ClassId == 0 || typeof (item.ClassId) == undefined) {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料未找到班组分工数据，提交被终止！");
                        return;
                    }
                }
                else if (MPState == "Change") {
                    if (item.MsState != "2" && item.MsState != "3") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                        return;
                    }

                }

            }
            else if (MPType == "成交" || MPType == "协A" || MPType == "协B") {
                if (item.MaterialCode != "") {
                    if (MPState == "Normal") {
                        if (item.OsState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                    }
                    else if (MPState == "Change") {
                        if (item.OsState != "2" && item.OsState != "3") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                            return;
                        }

                        if (item.OsReviewState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                            return;
                        }

                    }
                }
                else {
                    com.message("error", "序号为【" + item.Xuhao + "】的物料编码为空，提交被终止！");
                    return;
                }
            }
            else if (MPType == "机加报量") {

                if (MPState == "Normal") {
                    if (item.JsState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                        return;
                    }
                    if (item.Map == null || item.Map == "") {
                        com.message("error", "序号为【" + item.Xuhao + "】的图号为空，提交被终止！");
                        return;
                    }
                }
            }
            else if (MPType == "制作明细") {

                if (MPState == "All") {
                    if (item.MkState != "0" && item.MkState != "2" && item.MkState != "3") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交,变更删除,变更修改\"，提交被终止！");
                        return;
                    }

                    if ((item.Map == null || item.Map == "") && (item.Process == "1" || item.Process == "2")) {
                        com.message("error", "序号为【" + item.Xuhao + "】机加件图号为空，提交被终止！");
                        return;
                    }
                }
            }
            else if (MPType == "材料计划") {

                if (MPState == "Normal") {

                    if (item.MpState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                        return;
                    }
                }
                if (MPState == "Change") {
                    if (item.MpReviewState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                        return;
                    }
                }
            }
            else if (MPType = "外协计划") {

                if (MPState == "Normal") {
                    if (item.OsState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                        return;
                    }
                }
                if (MPState == "Change") {
                    if (item.OsReviewState != "0") {
                        com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                        return;
                    }
                }
            }
            Ids = Ids + item.ID + ",";
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=SubmitOrgData",
            data: { MPState: Bom.settings.MPState, OrgData: Ids, MPType: Bom.settings.MPType, TaskCode: Bom.settings.TaskCode, TaskId: Bom.settings.TaskId },
            success: function (data) {
                if (data.state == "error") {
                    com.message("error", data.msg);
                }
                else {
                    $("#tbList").datagrid("unselectAll");
                    var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                    $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                    if (data.returnValue && data.returnValue != null) {
                        top.wrapper.addTab(data.returnValue.split('|')[1], data.url);
                    }



                }

            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}



Bom.CalCulateWeight = function () {
    com.ajax({
        url: "/Logic/TM/OrgDataAjax.aspx?method=CalCulateWeight", data: { taskId: Bom.settings.TaskId }, success: function (data) {
            com.message(data.state, data.msg, function () {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                $("#tbList").datagrid("unselectAll");
                $("#lblTaskWeight").html(data.returnValue);
            })
        }
    });
}


Bom.CheckKuWeight = function () {
    top.wrapper.addTab("核对库重量", "/UI/TM/OrgDataCheckKuWeight.aspx?TaskId=" + Bom.settings.TaskId);
    //var rows = $("#tbList").datagrid("getSelections");
    //if (rows.length != 0) {
    //    com.ajax({
    //        url: "/Logic/TM/OrgDataAjax.aspx?method=CheckKuWeight", data: { taskId: Bom.settings.TaskId, data: JSON.stringify(rows) }, success: function (data) {
    //            com.message(data.state, data.msg)
    //        }
    //    });
    //}
    //else {
    //    com.message("information", "请至少选择一条数据");
    //}
}

Bom.ExportExcel = function () {
    var taskId = $("#TaskId").val();
    //alert(taskId);
    //var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
    var high = com.getHighSearchList();
    var highSerach = high.highSearchData;
    top.wrapper.addTab("导出Excel", "/ExportModel/OrgDataExport.aspx?searchData=" + com.serializeSearchArray1("form1") + "&highsearchData=" + highSerach + "&MPState=" + Bom.settings.MPState + "&MPType=" + Bom.settings.MPType + "&SubmitType=" + Bom.settings.SubmitType) + "&TaskId=" + taskId;
}


Bom.AdjustMsDetail = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0 && rows.length < 2) {
        var row = $("#tbList").datagrid("getSelected");
        top.wrapper.addTab("明细调整模式", "/UI/TM/OrgMsAdjustNew.aspx?TaskId=" + Bom.settings.TaskId + "&OrgId=" + row.ID + "&Xuhao=" + row.Xuhao);
    }
    else {
        com.message("information", "请选择一行")
    }

}

Bom.OrgTreeDetail = function () {
    var rows = $("#tbList").datagrid("getSelections");

    if (rows.length == 0) {
        top.wrapper.addTab("层级关系模式", "/UI/TM/OrgMsAdjust.aspx?TaskId=" + Bom.settings.TaskId + "&Xuhao=*");
    }
    else if (rows.length > 0 && rows.length < 2) {
        var row = $("#tbList").datagrid("getSelected");
        top.wrapper.addTab("层级关系模式", "/UI/TM/OrgMsAdjust.aspx?TaskId=" + Bom.settings.TaskId + "&OrgId=" + row.ID + "&Xuhao=" + row.Xuhao);

    }
    else {
        com.message("information", "请选择一行")
    }


}



$(Bom.init);